<?php

namespace app\shop\controller\store;

use app\Request;
use app\shop\controller\Controller;
use app\shop\model\store\Remarks as RemarksModel;


/**
 * 门店控制器
 */
class Remarks extends Controller
{
    /**
     * 门店列表
     */
    public function index()
    {
        $params = $this->postData();

        $model = new RemarksModel;

        $list = $model->getList($params);

        return $this->renderSuccess('', compact('list'));
    }


    /**
     * 添加门店
     */
    public function add()
    {
        $model = new RemarksModel;

        $data = $this->postData();

        // 新增记录
        if ($model->add($data)) {
            return $this->renderSuccess('添加成功');
        }
        return $this->renderError($model->getError() ?: '添加失败');
    }


    /**
     * 修改门店信息
     */
    public function edit($id)
    {

        $model = RemarksModel::detail($id);
        if ($this->request->isGet()) {
            return $this->renderSuccess('', compact('model'));
        }
        // 修改记录
        if ($model->edit($this->postData())) {
            return $this->renderSuccess('更新成功');
        }
        return $this->renderError($model->getError() ?: '更新失败');
    }


    /**
     * 软删除
     */
    public function delete($id)
    {
        $model = new RemarksModel;
        // 门店详情
        if (!$model->setDelete(['id' => $id])) {
            return $this->renderError('删除失败');
        }
        return $this->renderSuccess($model->getError() ?: '删除成功');

    }





}
